package test;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.Scanner;





public class Demo04 {

    public static void main(String[] args) throws Exception {

/**

 * 登录注册

 * 获取用户输入内容

 * 把输入的内容当做条件查询数据库中的内容

 */

        String name = "sc.nextLine()";
        String pwd = "sc.nextLine()";

// 注册驱动

        Class.forName("com.mysql.jdbc.Driver");

/*

String url = "jdbc:mysql://localhost:3306/class?useSSL=false";

String user = "root";

String password = "root";

// 获取和数据库的连接

Connection conn = DriverManager.getConnection(url, user, password);*/

        Connection conn = JDBCUtil.getConnection();

// 使用连接对象获取执行sql的对象

        Statement stmt = conn.createStatement();

// 编写SQL语句

        String sql = "select * from userinfo where username='"+name+"' and password='"+pwd+"'";

        System.out.println(sql);

// 执行SQL语句，获取返回结果

        ResultSet resultSet = stmt.executeQuery(sql);

        if (resultSet.next()) {

            System.out.println("登陆成功！");

        } else {

            System.out.println("用户名或密码错误！");

        }

        JDBCUtil.releaseSourse(conn, stmt, resultSet);



    }

}